package cn.iocoder.yudao.module.promotion.gift.dao;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.business.basic.dao.mapper.CoreMapper;
import cn.iocoder.yudao.framework.business.basic.dao.query.CoreLambdaQueryWrapper;
import cn.iocoder.yudao.module.promotion.gift.pojo.po.GiftScanConfig;
import org.apache.ibatis.annotations.Mapper;

import java.util.ArrayList;
import java.util.List;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * Mapper 接口
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/05/27
 */
@Mapper
public interface GiftScanConfigMapper extends CoreMapper<GiftScanConfig> {

    default List<Long> selectGiftActivityIds(Long shopId, Integer price) {
        CoreLambdaQueryWrapper<GiftScanConfig> wrapper = new CoreLambdaQueryWrapper<>();
        wrapper.select(GiftScanConfig::getGiftActivityIds);
        wrapper.eq(GiftScanConfig::getShopId, shopId);
        wrapper.le(GiftScanConfig::getGiveUsePrice, price);
        List<GiftScanConfig> list = selectList(wrapper);
        if (CollUtil.isEmpty(list)) {
            return List.of();
        }
        List<Long> ids = new ArrayList<>();
        for (GiftScanConfig item : list) {
            if (CollUtil.isNotEmpty(item.getGiftActivityIds())) {
                ids.addAll(item.getGiftActivityIds());
            }
        }
        return ids;
    }

}
